/*
 *	This file is part of Lounge-Cast.
 *
 *  Author:  	Markus Moormann
 *	E-mail:  	mmoorman@uni-osnabrueck.de
 *	Copyright:	University of Osnabrueck (Zentrum Virtuos)
 * 	Website:	www.uni-osnabrueck.de
 *	Date:		16.02.2011
 *
 *	Lounge-Cast is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *	Lounge-Cast is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Lounge-Cast.  If not, see <http://www.gnu.org/licenses/>.
 */
package multimedia.view.renderer
{
	import multimedia.model.vo.FeedItemVO;
	
	import mx.controls.listClasses.ListItemRenderer;

	public class FeedItemRenderer extends ListItemRenderer
	{

		private var _updateStatus:UpdateFeedItemStatusButton;
		private var _createTextMedia:CreateTextFromFeedItemButtonRenderer;
		private var _feedItem:FeedItemVO;

		public function FeedItemRenderer()
		{
			super();
		}

		override public function set data(value:Object):void
		{
			super.data = value;
			if(label != null && value != null)
			{
				label.text = (value as FeedItemVO).title;
			}
		}

		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			if (super.data)
			{
				if (_updateStatus == null)
				{
					_updateStatus = new UpdateFeedItemStatusButton();
					_updateStatus.x = this.width - _updateStatus.width - 5;
					addChild(_updateStatus);
				} else
				{
					_updateStatus.x = this.width - _updateStatus.width - 5;
				}
				
				if(_createTextMedia == null)
				{
					_createTextMedia = new CreateTextFromFeedItemButtonRenderer();
					_createTextMedia.x = this.width - _updateStatus.width - _createTextMedia.width - 10;
					addChild(_createTextMedia);
				}else
				{
					_createTextMedia.x = this.width - _updateStatus.width - _createTextMedia.width - 10;
				}
				
				
				_updateStatus.node = super.data as FeedItemVO;
				_createTextMedia.node = super.data as FeedItemVO;
				
				label.text = (super.data as FeedItemVO).title;
				label.width = this.width - _updateStatus.width - _createTextMedia.width - 10;
			}
		}

	}
}